﻿namespace Nello
{
    using System;

    internal class StringRandom
    {
        private Random _rnd = new Random(DateTime.Now.Millisecond);
        private string _strout;

        private string GetOneRandomNum(string strformat)
        {
            string CS40001 = strformat;
            if (CS40001 == null)
            {
                return strformat;
            }
            if (!(CS40001 == "*"))
            {
                if (CS40001 == "#")
                {
                    return this._rnd.Next(10).ToString();
                }
                if (CS40001 == "$")
                {
                    return Convert.ToChar((int) (this._rnd.Next(0x1a) + 0x41)).ToString();
                }
                return strformat;
            }
            if (this._rnd.Next(0x24) < 10)
            {
                return this._rnd.Next(10).ToString();
            }
            return Convert.ToChar((int) (this._rnd.Next(0x1a) + 0x41)).ToString();
        }

        public string GetRandomString()
        {
            return this.GetRandomString(8);
        }

        public string GetRandomString(int bits)
        {
            string ss = "*".PadLeft(bits, '*');
            return this.GetRandomString(ss);
        }

        public string GetRandomString(string templatestr)
        {
            this._strout = string.Empty;
            for (int i = 0; i < templatestr.Length; i++)
            {
                char CS00001 = templatestr[i];
                this._strout = this._strout + this.GetOneRandomNum(CS00001.ToString());
            }
            return this._strout;
        }

        public static StringRandom Instance
        {
            get
            {
                return new StringRandom();
            }
        }
    }
}

